layui.define(['layer', 'form', 'upload'], function (exports) {
    var $ = layui.$
        , layer = layui.layer
        , laytpl = layui.laytpl
        , setter = layui.setter
        , view = layui.view
        , admin = layui.admin
        , form = layui.form
        , upload = layui.upload;

    var $body = $('body')
        , userId;

    // 回车提交表单
    document.onkeydown = function (e) {
        // 兼容FF和IE和Opera
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            $('#submitBut').click();
        }
    }

    // 加载客户信息
    admin.req({
        url: layui.setter.ctx + '/system/sysUser/getLoginInfo'
        , type: 'get'
        , done: function (res) {
            //表单赋值
            form.val('userInfoForm', {
                "userId": res.data.userId
                ,"username": res.data.userName
                , "nickName": res.data.nickName
                , "sex": res.data.sex
                , "avatar": res.data.avatar
                , "phonenumber": res.data.phonenumber
                , "email": res.data.email
            });
        }
    });

    //确认修改
    form.on('submit(setmyinfo)', function (obj) {
        // 请求公钥
        admin.req({
            url: layui.setter.ctx + '/system/sysUser/edit'
            , type: 'put'
            , data: JSON.stringify(obj.field)
            , contentType: 'application/json'
            , done: function (res) {
                layer.msg(res.msg, {icon: 1});
            }
        });
    });

    //对外暴露的接口
    exports('userInfo', {});
});